package org.vaadin.gwtgraphics.testapp.client;

import org.vaadin.gwtgraphics.client.DrawingArea;
import org.vaadin.gwtgraphics.client.Group;
import org.vaadin.gwtgraphics.client.animation.Animate;
import org.vaadin.gwtgraphics.client.shape.Rectangle;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.regexp.shared.MatchResult;
import com.google.gwt.regexp.shared.RegExp;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class Test implements EntryPoint {

  final Group g = new Group();
  
	public void onModuleLoad() {
//		InteractiveTestApplication test = new InteractiveTestApplication();
	  
	  VerticalPanel panel = new VerticalPanel();
	  
	  DrawingArea area = new DrawingArea(400, 400);
	  final Rectangle r  = new Rectangle(100, 100, 40, 40);
	  g.add(r);
	  g.add(new Rectangle(120, 120, 40, 40));
	  area.add(g);
	  
	  Button animate = new Button("Anim");
	  animate.addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent event) {
        int x = g.getX();
        int y = g.getY();
        
        int dx = oposite(x)==0?50:oposite(x);
        int dy = oposite(y)==0?50:oposite(y);
                      
        Animate a = new Animate(g, "x", x, dx, 2000);
        Animate a2 = new Animate(g, "y", y, dy, 2000);
        a.start();
        a2.start();
      }
      
      private int oposite(int a){
        return -1*a;
      }
    }); 
	  
	  panel.add(area);
	  panel.add(animate);
	  
		RootPanel.get().add(panel);
		
//		String xform = "translate(-20 -10) ";
//		MatchResult matchResult = RegExp.compile("translate\\(\\s*(\\-?\\d+)\\s*([, ]\\s*(\\-?\\d+))?\\s*\\)","i").exec(xform);
//		
//		GWT.log(""+matchResult);
		
	}
}
